package com.lanou3g.musicenjoy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou3g.musicenjoy.R;
import com.lanou3g.musicenjoy.entity.RecomGride;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 15/10/23.
 */
public class RecomGrideAdapter extends BaseAdapter{
    private List<RecomGride.ContentEntity.ListEntity> data;
    private Context context;
    public RecomGrideAdapter(Context c){
        context=c;
    }
    public void iniData(List<RecomGride.ContentEntity.ListEntity> data){
        if (this.data==null){
            this.data=new ArrayList<RecomGride.ContentEntity.ListEntity>();
        }else {
            this.data.clear();
        }
        this.data=data;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return data!=null&&data.size()>0?data.size():0;
    }

    @Override
    public Object getItem(int position) {
        return data!=null&&data.size()>0?data.get(position):null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(
                    R.layout.fragment_recommendation_gride,null);
            holder=new ViewHolder();
            holder.imageView= (ImageView) convertView.findViewById(R.id.grideImageView);
            holder.textView= (TextView) convertView.findViewById(R.id.grideNum);
            holder.view= (TextView) convertView.findViewById(R.id.grideTextView);
            convertView.setTag(holder);

        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        RecomGride.ContentEntity.ListEntity entity= (RecomGride.ContentEntity.ListEntity) getItem(position);
        Picasso.with(context).load(entity.getPic()).into(holder.imageView);
        holder.textView.setText(entity.getListenum());
        holder.view.setText(entity.getTitle());
        return convertView;
    }
    private class ViewHolder{
      private ImageView imageView;
        private TextView textView;
        private TextView view;
    }
}
